--==============================
--[[ 招财buff相关定义 ]]
--==============================
local function bring_wealth_onkilled(inst, data)
    local victim = data.victim
    if victim ~= nil and victim.components.health ~= nil and (not victim:HasTag("player")) and (not victim:HasTag("wall")) then
        local inventory = inst.components.inventory or inst.components.container
        if inventory == nil then
            return
        end
        if victim.components.health.maxhealth >= 10 and victim.components.health.maxhealth < 2500 then
            local item = SpawnPrefab("bboy_copper_coin")
            inventory:GiveItem(item, nil, victim:GetPosition())
        elseif victim.components.health.maxhealth >= 2500 then
            local item = SpawnPrefab("bboy_copper_coin")
            if item.components.stackable then
                item.components.stackable:SetStackSize(10)
            end
            inventory:GiveItem(item, nil, victim:GetPosition())
        end
    end
end

--==============================
--[[ buff列表 ]]
--==============================
local buffs = {
    -- 招财
    bring_wealth = {
        duration = 360,                       -- buff时长
        priority = 1,                         -- 优先级
        onattachedfn = function(inst, target) -- buff触发的执行函数
            target:ListenForEvent("killed", bring_wealth_onkilled)
        end,
        onextendedfn = function(inst, target) -- buff存在期间，添加了相同buff的执行函数
        end,
        ondetachedfn = function(inst, target) -- buff结束时的执行函数
            target:RemoveEventCallback("killed", bring_wealth_onkilled)
        end,
    },
}

return buffs
